<?php

/**
 * @author Martin Pernica
 * @copyright 2009
 */

class Log extends System{

	public $handler;

	public function __construct($handler){
		$this->handler = $handler;
	}

	public function write($level, $component, $date, $message, $user){
		if($this->handler == 'database'){
			$date = ($date == 'NOW()') ? $date : '$date';
			$ip = (getenv('HTTP_X_FORWARDED_FOR')) ?  getenv('HTTP_X_FORWARDED_FOR') :  getenv('REMOTE_ADDR');
			$query = parent::$db->query("INSERT INTO {prefix}log (level, component, date, message, user, ip) VALUES ('".$level."', '".$component."', ".$date.", '".$message."', '".$user."', '".$ip."')");
			if($query){
				return true;
			}else{
				return false;
			}
		}
	}
}

?>